<?php
// Header 
$this->set('title_for_layout', __("Danh sách danh mục tin", true));
//$this->left_menu = 'menu/manage_categories';

$this->left_menu = 'menu/'.$this->params['controller'];
$params = array(
	//'root'	=>	$this->params['named']['root']
);
if (isset($this->params['plugin'])) {
	$params['plugin'] = $this->params['plugin'];
} else {
	$params['plugin'] = null;
}
if (isset($this->params['named']['root'])) {
	$params['root'] = $this->params['named']['root']; 
}

// Load Css
echo $this->Html->css('vista_button');
echo $this->Html->css('cake.form');
echo $this->Html->css('tree_table/jquery.acts_as_tree_table');
echo $this->Html->css('tree_table/master');

// Load Javascript
echo $this->Html->script('tree_table/jquery.acts_as_tree_table');
echo $this->Html->script('/news/css/manage_news_categories/index');
?>

<style>
<!--
#tree tr td {
	padding-top:5px;
	padding-bottom:5px;
}
#tree tr td.alt {
	background:#efefef;
	padding-top:5px;
	padding-bottom:5px;
}

#tree .first {
	padding-left:20px;
}

table tr td {
	text-align:left;
	vertical-align:middle;
}
.text_title {
	background: none;
}
div#AddSectionForm {
	display:none;
}

.text_title {
	background: none;
}
span.alias {
	font-style:italic;
}
span.field-name {
	font-weight:bold;
}
div#flashMessage {
	background:#FFFFFF;
	border:1px solid #dddddd;
	font-weight:bold !important;
	font-size:13px;
	text-align:center !important;
	margin:10px;
	display:none;
}
td.center {
	text-align:center;
}
-->
</style>
<?php echo $session->flash()?>

<div class='right_content'>

<div class="title_left_sidebar">
	<div class="text_title">
		<?php __("Danh sách danh mục")?>
	</div>
	<div class="create_edit">
		<div class="bd_title"></div>
		<div class="item_create">
			<div class="item_menu"><?php echo $html->image('toolbar/add.png', array('alt'=>__('Tạo mới danh mục',true), 'align'=>'left')) ?></div>
			<div class="category_mn"><a href="<?php echo $html->url($params + array('action'=>'add'))?>" id='add_new_category_link'><?php __("Tạo mới danh mục")?></a></div>
			<div class="clear"></div>
		</div>
		<div class="bd_title"></div>
	</div>
	
</div>

<div class="blank5"></div>

<script language="Javascript">
<!--
$(document).ready(function() {
	$("#tree").acts_as_tree_table({
		//indent : 5 
	});
});
-->
</script>
<?php function recursiveLoop($items, &$class, &$html, &$view, &$configs, &$params){
	$content = "";
	foreach ($items as $item) {
		$class = $class == '' ? 'altrow' : '';
		$content .= "";
		if (isset($item['items']) && $configs['Category']['manager']['expand_list']) {
			$content .= "
			<tr id=\"node-".$item['NewsCategory']['id']."\" class='{$class} child-of-node-".$item['NewsCategory']['parent_id']." expanded'>
			<td class='first'>
				<span class='folder field-name'>".$item['NewsCategory']['name']."</span><br/>
				<span class='alias'>".$item['NewsCategory']['alias']."</span>
			</td>";
		} else if (isset($item['items']) && !$configs['Category']['manager']['expand_list']) {
			$content .= "
			<tr id=\"node-".$item['NewsCategory']['id']."\" class='{$class} child-of-node-".$item['NewsCategory']['parent_id']." collapsed'>
			<td class='first'>
				<span class='folder field-name'>".$item['NewsCategory']['name']."</span><br/>
				<span class='alias'>".$item['NewsCategory']['alias']."</span>
			</td>";
		} else {
			$content .= "
			<tr id=\"node-".$item['NewsCategory']['id']."\" class='{$class} child-of-node-".$item['NewsCategory']['parent_id']."'>
			<td class='first'>
				<span class='folder field-name'>".$item['NewsCategory']['name']."</span><br/>
				<span class='alias'>".$item['NewsCategory']['alias']."</span>
			</td>";
		}
		
		$content .=	"
		<td class='{$class} center' align='center' nowrap valign='middle'>
			
			".$html->image('toolbar/button_edit.png', array('border'=>0))." ".$html->link(__('Sửa',true), $params + array('action'=>'edit',$item['NewsCategory']['id']), array('class'=>'edit_category_link'))." | 
			".$html->image('toolbar/button_del.png', array('border'=>0))." ".$html->link(__('Xóa',true), $params + array('action'=>'delete',$item['NewsCategory']['id']), array("onclick"=>__("return confirm('Bạn có thật sự muốn xóa danh mục tin này?');", true)))." 
			".$html->image('toolbar/button_up.png', array('border'=>0))." ".$html->link(__('Lên',true), $params + array('action'=>'move_up',$item['NewsCategory']['id']),array())." 
			".$html->image('toolbar/button_down.png', array('border'=>0))."
			".$html->link(__('Xuống',true), $params + array('action'=>'move_down',$item['NewsCategory']['id']),array())." 
		</td>
		</tr>";
		if (isset($item['items'])) {
			$content .= recursiveLoop($item['items'], $class, $html, $view, $configs, $params);
		}
	}
	return $content;
}?>


<!-- Begin tree table -->
<div class='right_table'>
<table id="tree" width="100%" cellspacing='1' class='form_background' cellpadding='0'>
	<tr>
		<th><a><?php __('Tên danh mục')?></a></th>
		
		<th width='220'><a><?php __('Chức năng')?></a></th>
	</tr>
	
	<?php echo recursiveLoop($tree, $class, $html, $this, $configs, $params);?>
	
</table>
</div>
<!-- End tree table -->

</div>
<?php //echo $this->element('sql_dump')?>